Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

module.exports.isInstance   A

Complexity

Conditions 1
Paths 3

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
c 1
b 1
f 0
nc 3
nop 2
dl 0
loc 3
rs 10
1
module.exports = {
2
  
3
  /**
4
   * Check whether the given object is an instance of the specified class.
5
   * The necessity for this is discussed in PR #13: https://github.com/rootsdev/gedcomx-js/pull/13
6
   * 
7
   * We put this functionality in a method to be DRY, even though it's short.
8
   * This could easily change in the future for correction and performance.
9
   * 
10
   * It could be handy to expose this on GedcomX somewhere so that users of the
11
   * library can use it too. But then we would need to add a way for them to
12
   * easily get the _gedxClass property without being tied to that private
13
   * property name. In other words, a static method such as Person.getClass()
14
   * 
15
   * @param {Object} obj
16
   * @param {String} className
17
   * @returns {Boolean}
18
   */
19
  isInstance: function(obj, className){
20
    return obj && Object.getPrototypeOf(obj) !== Object.prototype && obj._gedxClass === className;
21
  }
22
  
23
};